﻿<UserControl x:Class="MemoryClient.Views.PlayerInfo"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:MemoryClient.ViewModels"
             xmlns:own="clr-namespace:MemoryClient.Views"
             xmlns:att="clr-namespace:MemoryClient.AttachedProps"
             d:DesignHeight="500"
             d:DesignWidth="200"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>

            <DataTemplate DataType="{x:Type vm:PlayerViewModel}">
                <Grid Margin="5">

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Border Grid.ColumnSpan="2" Grid.RowSpan="3"
                        Name="PlayerInfoField" Background="Transparent" CornerRadius="10" Opacity="0.4" />

                    <Grid Grid.Column="0" Grid.Row="0"
                                Margin="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Grid.Row="0"
                                Text="Anzahl Paare: " Style="{StaticResource DefaultText}"/>
                        <TextBlock Grid.Column="1" Grid.Row="0"
                                Text="{Binding Path=Rack.NumberOfSets}" Style="{StaticResource DefaultText}"/>
                    </Grid>

                    <Grid Grid.Column="0" Grid.Row="2"
                                Margin="4">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Grid.Row="1"
                                Text="Daneben: " Style="{StaticResource DefaultText}" />
                        <TextBlock Grid.Column="1" Grid.Row="1"
                                Text="{Binding Path=MissCount}" Style="{StaticResource DefaultText}" />
                    </Grid>

                    <StackPanel Grid.Column="1" Grid.Row="0" Grid.RowSpan="3">
                        <Image Source="{Binding Path=AvatarFileName}" Height="64" Width="64" />
                        <TextBlock Text="{Binding Path=Name}" Style="{StaticResource DefaultText}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </StackPanel>

                    <ItemsControl Grid.Column="0" Grid.Row="1"
                                  ItemsSource="{Binding Path=Rack.DiscardedCards}" 
                             >
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel Orientation="Horizontal" IsItemsHost="True" Margin="22,16,0,0" DataContext="{Binding}" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Path=IsCurrent}" Value="true">
                        <Setter TargetName="PlayerInfoField" Property="Background" Value="LightBlue" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate DataType="{x:Type vm:CardSetViewModel}">
                <Border BorderBrush="Black" 
                        BorderThickness="1" 
                        CornerRadius="4" 
                        Width="24" 
                        Height="24"
                        HorizontalAlignment="Left"
                        Margin="-17,-12,0,0"                        
                        Background="White">
                    <Image Source="{Binding Path=Card1.CardSymbol.FileName}" />
                </Border>
            </DataTemplate>

            <Style TargetType="{x:Type StackPanel}" x:Key="StackPanelAnimationStyle">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=Game.IsGameRunning}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard >
                                    <DoubleAnimation From="5"  To="200" Storyboard.TargetProperty="Width" Duration="0:00:00.6"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard >
                                    <DoubleAnimation From="200"  To="5" Storyboard.TargetProperty="Width" Duration="0:00:00.6"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
        
    </UserControl.Resources>
    <Border Style="{StaticResource GrayBorderStyle}" Margin="5">

        <StackPanel Width="5" Style="{StaticResource StackPanelAnimationStyle}">
            <ItemsControl ItemsSource="{Binding Path=Game.PlayerHandler.AllPlayers}" />
        </StackPanel>
        
    </Border>
</UserControl>
